import echarts from 'echarts'

require('echarts/theme/macarons')
export default {
  mounted() {
    this.chart = echarts.init(document.getElementById(this.id), 'macarons')
    this.chart.setOption(this.chartData)
    this.resizeChart = () => {
      setTimeout(() => {
        this.chart.resize()
      }, 0)
    }
    window.addEventListener('resize', this.resizeChart)
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.resizeChart)
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  }
}
